<template>
  <div class="max login_main">
    <my-header :backBtn="true"></my-header>

    <div class="cont-noh">
      <div class="bind-input">
        <div class="weui-cells weui-cells_form">
          <div class="weui-cell my-weui-cell">
            <div class="weui-cell__hd"><label class="weui-label bind-weui-label tl">用户名</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" value="请输入正确的用户名" v-model="formData.username" placeholder="请输入用户名"
                     @focus="phoneError = true"/>
            </div>
          </div>
        </div>
      </div>
      <div class="bind-input">
        <div class="weui-cells weui-cells_form">
          <div class="weui-cell my-weui-cell">
            <div class="weui-cell__hd"><label class="weui-label bind-weui-label tl">密码</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="password" v-model="formData.pwd" placeholder="请输入密码"/>
            </div>
          </div>
        </div>
      </div>
      <div class="button-sp-area">
        <a href="javascript:;" class="weui-btn weui-btn_primary my-weui-btn" @click="login">绑 定</a>
        <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default" @click="cancel">取消</a>
      </div>
      <div style="float: left;margin: 2rem">当前绑定角色：<label style="font-weight: bold">{{formData.loginType==='kindergarten'?'园长':'教师'}}。</label></div>
    </div>
  </div>
</template>

<script>

  import myHeader from '@/components/Header.vue'
  import wx from "weixin-js-sdk";

  export default {
    components: {
      myHeader
    },
    data() {
      return {
        formData: {
          pwd: '',
          openId: '',
          username: '',
          loginType: '',
          kindergartenId:''
        },
      }
    },
    methods: {
      cancel() {
        wx.closeWindow();
      },
      back() {
        this.$router.push('/login')
      },
      login() {
        this.$http.bindGardener(this.formData).then(resp => {
          let data = resp.data;
          this.$Cookies.set('token', data.token);
          this.$Cookies.set('fullName', data.fullName);
          this.$Cookies.set('loginType', data.loginType);
          this.$Cookies.set('headImage', data.headImage);
          this.$router.push('/home');
        })
      },
    },
    created() {
      this.formData.openId = this.$route.query.openId;
      this.formData.loginType = this.$route.query.loginType;
      this.formData.kindergartenId = this.$route.query.kindergartenId;
    }
  }
</script>

<style scoped>

  .bind-input {
    width: 80%;
    margin: 5rem auto;
  }
</style>
